<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Role extends Model
{
    use SoftDeletes;
    protected $primaryKey = 'id';
    protected $table = 'roles';
    public $timestamps = false;
    public $guarded = [];
    const UPDATED_AT = null;
    const CREATED_AT = null;
    protected $hidden = ['deleted_at'];
    /**
     * 权限和用户的多对多
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function belongsToUser(){
        return $this->belongsToMany(User::class, 'user_roles', 'role_id', 'user_id');
    }

    /**
     * 权限和路由的多对多
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function belongsToRoute(){
        return $this->belongsToMany(Route::class, 'route_roles', 'role_id', 'route_id');
    }
}
